/**********************, *****************************************************************
Firm-embedded productivity and cross-country income differences
Alviarez, Cravino and Ramondo
Journal of Political Economy (2022)

Program: table_F1_share_domesticsales.do
Date: October 2022

Description: Reproduces Table F.1: Share of domestic sales in total revenues: foreign MNE affiliates vs. all firms.

*****************************************************************************************/

*-------------------------------------------------------------------------------
global typeden=1
include "set_directories.do"
set memory 64g
global lf "LF"

*Log
cap log close
log using "${clogs}/table_F1_share_domesticsales.log",replace
*-------------------------------------------------------------------------------




*Calculating the share of domestic sales in total revenues: foreign MNE affiliates vs. all firms.
*------------------------------------------------------------------------
clear all
use "${data}/klems_oecd_unido_orbis_sales_emp_exp.dta", clear
keep year isocode sector* exports EXP_usd_mnc GO_usd GO_usd_mnc
order year isocode sector1 sector GO_usd exports GO_usd_mnc EXP_usd_mnc
drop if sector1== sector

collapse (sum) GO_usd exports GO_usd_mnc EXP_usd_mnc, by(year isocode sector1)
keep if year==2016
keep if isocode=="EE" | isocode=="ES" | isocode=="IT" | isocode=="JP" | isocode=="SE" | isocode=="US" 

*Domestic intensity 
*----------------------------------------------
keep if sector1=="Manufacturing (C)" | sector1=="Market_Services (G-H-I-J-K-M-N-R-S-T)"
gen xx=exports/GO_usd
gen yy=EXP_usd_mnc/GO_usd_mnc

gen economy= 1-(exports/GO_usd)
gen mnc= 1-(EXP_usd_mnc/GO_usd_mnc)
gen ratio=economy/mnc
sort  year isocode sector1
drop xx yy 

gen type="NA"
replace type="_manuf" if sector1=="Manufacturing (C)"
replace type="_serv" if sector1=="Market_Services (G-H-I-J-K-M-N-R-S-T)"

keep year isocode economy mnc ratio type
reshape wide economy mnc ratio , i(year isocode) j(type) string
format %9.2fc *manuf *serv

export delimited using "${rappendix}/table_F1_share_domesticsales.csv", datafmt replace
log close 






